# -*- coding: utf-8 -*-
# @Author   : xiongjianwen
# @Time     : 2022/10/31 8:59
# @File     : winappdriver_demo.py
# @Project  : BwProCost_Auto_v2

import time, os
from appium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from time import sleep


class Auto():

    def __init__(self, host='localhost', port=4727):
        # 打开WinAppDriver服务
        # 注意：如果手动开启，则可以注释掉
        # os.system(r'start "" /d "C:\Program Files\Windows Application Driver\"  "WinAppDriver.exe"')

        # 配置信息
        # 包含：平台名、系统、应用程序绝对路径
        desired_caps = {'platformName': 'Windows', 'deviceName': 'WindowsPC',
                        'app': r"D:\博微软件\技改检修工程计价通T1软件_1.7.4.201\BT1.exe"}

        try:
            # 连接WinAppDriver服务，打开目标软件
            self.driver = webdriver.Remote('http://{}:{}'.format(host, port), desired_caps)
        except Exception as e:
            raise AssertionError(e)
    def login_software(self):
        self.driver.find_element_by_name('   确定   ').click() # 这种快
        self.driver.find_element_by_name('   登录   ').click()

    def test_software(self):
        self.driver.find_element_by_xpath('//Button[starts-with(@Name,"新    建")]').click() # 这种慢，类似于uiautomation的定位
if __name__ == '__main__':
    auto = Auto()
    # auto.open_software()
    # auto.login_software()
    auto.test_software()